package dao;

import util.Dbconnection;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;

public class UserDao {

	public static boolean deng(String name, String pwd) {
		Connection conn = null;
		Statement stat = null;
		ResultSet rs = null;
		String sql = "select * from login where admin='" + name
				+ "'and password='" + pwd + "'";
		try {
			conn = Dbconnection.getcConnection();
			stat = conn.createStatement();
			rs = stat.executeQuery(sql);
			if (rs.next()) {
				return true;
			}

		} catch (Exception e) {
			e.printStackTrace();
		}

		return false;
	}

	public static int xiu(String name, String pwd) {
		Connection conn = null;
		PreparedStatement ps = null;
		int rs;
		String sql = "insert into deng(username,userpwd) values(?,?)";
		System.out.println(sql);
		try {
			conn = Dbconnection.getcConnection();
			ps = conn.prepareStatement(sql);
			//ps.setInt(1, id);
			ps.setString(1, name);
			ps.setString(2, pwd);
			return rs=ps.executeUpdate();

		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			Dbconnection.close(conn, ps, null);
		}

		return 0;
	}

}
